package com.bnzj.cloud.business.core.service;

import com.bnzj.cloud.business.core.persistence.entity.SysDictionary;
import com.bnzj.cloud.business.core.persistence.repository.SysDictionaryRepository;
import com.bnzj.core.persistence.BaseService;
import com.bnzj.core.persistence.query.QueryHelpBean;

import java.util.Optional;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author barry
 * @date 2019-09-27
 */
@Service
public class SysDictionaryService extends BaseService<SysDictionaryRepository, SysDictionary, Long> {

    public static QueryHelpBean getQueryHelpBean() {
        String selectSQL = "select d.*, dt.code type_code, dt.name type_name";
        String whereSQL = " from bnz_sys_dictionary d, bnz_sys_dictionary_type dt where d.type_id = dt.id ";
        QueryHelpBean queryBean = new QueryHelpBean(selectSQL + whereSQL, "select count(1)" + whereSQL, SysDictionary.class, false);
        return queryBean;
    }

    @Transactional(rollbackFor = Exception.class)
    public void deleteById(Long id) {
        this.repository.deletedById(id);
    }
    
    public Optional<SysDictionary> findByTypeAndName(String typeCode,String name) {
    	return repository.findByTypeAndName(typeCode, name);
    }
}
